<?php
require_once('common.php');
C('webtitle','网站管理后台');
C('pageid','index');
$index='1';
include_once 'common.head.php';
if($_GET['type']=="add"){
$con=$_POST['con'];
$addtime=date('Y-m-d');
if ($db->query("insert into {$prefix}gonggao (con,addtime) values ('$con','$addtime')")) {
						exit("<script language='javascript'>alert('公告添加成功！');window.location.href='ggset.php';</script>");
                    } else {
						exit("<script language='javascript'>alert('添加公告失败');window.location.href='ggset.php';</script>");
}
}
if($_GET['type']=="edits"){
$id=$_GET['id'];
$con=$_POST['con'];
if ($db->query("update {$prefix}gonggao set con='{$con}' where id='$id'")) {
						exit("<script language='javascript'>alert('公告编辑成功！');window.location.href='ggset.php';</script>");
                    } else {
						exit("<script language='javascript'>alert('编辑公告失败');window.location.href='ggset.php';</script>");
}
}
if($_GET['type']=='del'){
	$id=$_GET['id'];
	if (!$db->query("delete from {$prefix}gonggao where id='$id'")){
	exit("<script language='javascript'>alert('删除公告成功！');window.location.href='ggset.php';</script>");
	}
}
?>
<div class="animated fadeInRight">
<div class="row  border-bottom white-bg dashboard-header">
		<div class="wrapper wrapper-content">
            <div class="row">
			<?php
			if($_GET['type']!="edit"){
			?>
			<div class="ibox float-e-margins">
			<div class="ibox-title">
                        <h5>发布一个新公告 </h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
            </div>
			<div class="ibox-content">
			<div class="list-group">
			<form action="?type=add" role="form" class="form-horizontal" method="post">
			<input type="hidden" name="do" value="new">
			<div class="list-group-item">
				<div class="input-group">
					<div class="input-group-addon">公告内容</div>
					<textarea class="form-control" name="con" rows="5" placeholder="输入公告内容"></textarea>
				</div>
			</div>

			<div class="list-group-item">
				<input type="submit" name="submit" value="添加" class="btn btn-primary btn-block">
			</div>
			</form>
		</div>
</div></div>
<?php
			}else{
			$id=$_GET['id'];
			if(!$row=$db->get_row("select * from {$prefix}gonggao where id='$id' limit 1")){
			exit("<script language='javascript'>alert('要编辑的公告不存在！');window.location.href='ggset.php';</script>");
			}
?>
<div class="ibox float-e-margins">
			<div class="ibox-title">
                        <h5>编辑公告 </h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
            </div>
			<div class="ibox-content">
			<div class="list-group">
			<form action="?type=edits&id=<?=$id?>" role="form" class="form-horizontal" method="post">
			<input type="hidden" name="do" value="new">
			<div class="list-group-item">
				<div class="input-group">
					<div class="input-group-addon">公告内容</div>
					<textarea class="form-control" name="con" rows="5" placeholder="编辑公告内容"><?=$row['con']?></textarea>
				</div>
			</div>

			<div class="list-group-item">
				<input type="submit" name="submit" value="修改" class="btn btn-primary btn-block">
			</div>
			</form>
		</div>
</div></div>
<?php
			}
?>
<div id="vertical-timeline" class="vertical-container dark-timeline">
<?php if($rows=$db->get_results("select * from {$prefix}gonggao where 1=1 order by id desc limit 5")){ foreach($rows as $row){?>
					<div class="vertical-timeline-block">
                                        <div class="vertical-timeline-icon navy-bg">
                                            <i class="fa fa-briefcase"></i>
                                        </div>
										
<div class="vertical-timeline-content">
<p><?=$row['con']?><a href="?type=edit&id=<?=$row['id']?>"> [编辑] </a> <a href="?type=del&id=<?=$row['id']?>"> [删除] </a></p>
<span class="vertical-date">
<small><?=$row['addtime']?></small></span>
</div>
                        </div>
<?php }}?>


</div>
		</div>
	</div>
    </div></div>
	  <?php
include_once 'common.foot.php';
?>